﻿/*********************************************************************
 *
 *                             NOTICE
 *               COPYRIGHT (c) 2012 Panoscopix Software, Inc.
 *                UNPUBLISHED - ALL RIGHTS RESERVED
 * 
 *      This program is confidential, proprietary, and a trade
 *   secret of Panoscopix Software, Inc. The receipt or possession of
 *     this program does not convey any rights to reproduce or
 *      disclose its contents, or to manufacture, use, or sell
 *       anything that it may describe, in whole or in part, 
 *   without the specific written consent of Panoscopix Software, Inc.
 *
 * Command Stack Manager, which holds two
 * LIFO queues, namely, a done queue (for Commands that have
 * been executed or redone) and an undone queue (for Commands that
 * have been undone).
 * 
 *******************************************************************/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using FileSystem;
using FileSystem.Utility;

namespace FileSystem.Impl
{
    class CommandStackManager : ICommandStackManager
    {
        private ICommandStack doneStack;
        private ICommandStack undoneStack;

        public CommandStackManager()
            : this(new CommandStack(), new CommandStack())
        {
            //intentionally empty.
        }

        public CommandStackManager(ICommandStack doneStack, ICommandStack undoneStack)
        {
            this.doneStack = doneStack;
            this.undoneStack = undoneStack;
        }

        public ICommandStack done()
        {
            return doneStack;
        }

        public ICommandStack undone()
        {
            return undoneStack;
        }

        public String describe(IPrintContext context)
        {
            StringBuilder rc = new StringBuilder();
            rc.Append(context.getFormattedString("CommandStackManager:"));
            context.increaseIndent();

            rc.Append(context.getFormattedString("The Done Stack:"));
            context.increaseIndent();
            rc.Append(doneStack.describe(context));
            context.decreaseIndent();

            rc.Append(context.getFormattedString("The Undone Stack:"));
            context.increaseIndent();
            rc.Append(undoneStack.describe(context));
            context.decreaseIndent();

            context.decreaseIndent();
            rc.Append(context.getFormattedString("End of CommandStackManager"));
            return rc.ToString();
        }
    }
}
